package com.wlr.study.leetcode;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class LeetCode169 {
    public static int majorityElement(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        int value = nums.length / 2;
        int i = 0;
        while (i < nums.length) {
            map.put(nums[i], map.getOrDefault(nums[i], 0) + 1);
            i++;
        }
        for (Map.Entry<Integer, Integer> integerIntegerEntry : map.entrySet()) {
            if (integerIntegerEntry.getValue() > value) {
                return integerIntegerEntry.getKey();
            }
        }
        return nums[0];
    }

    public static void main(String[] args) {
        LeetCode169.majorityElement(new int[]{3, 2, 3});
    }
}
